<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加用户</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
	</head>
	<body class="easyui-layout">
		<div class="easyui-container-fluid">
			<div class="easyui-panel" style="width:100%;border: none;">
                            <div id="nav" class="nav">
                              
                            </div>
                            <div class="easyui-panel" title="添加用户" style="width:100%;max-width:400px;padding:30px 60px;">
                                   <form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
                                          <div style="margin-bottom:20px">
                                                 <input class="easyui-textbox" name="username" style="width:100%" data-options="label:'用户名:',required:true">
                                          </div>
                                          <div style="margin-bottom:20px">
                                                 <input class="easyui-passwordbox" name="password" style="width:100%" data-options="label:'密码:',required:true">
                                          </div>
                                          <div style="margin-bottom:20px">
                                                 <select class="easyui-combobox" name="department" label="部门：" style="width:100%">
                                                      <option value="manager">管理部</option>
                                                      <option value="channel">渠道部</option>
                                                      <option value="product">产品部</option>
                                                      <option value="sales">销售部</option>
                                                 </select>
                                          </div>
                                          <div style="margin-bottom:20px">
                                                 <select class="easyui-combobox" name="role" label="角色：" style="width:100%">
                                                      <option value="superadmin">超级管理员</option>
                                                      <option value="channel">渠道管理员</option>
                                                      <option value="product">产品管理员</option>
                                                 </select>
                                          </div>
                                   </form>
                                   <div style="text-align:center;padding:5px 0">
                                          <a href="javascript:void(0)" class="easyui-linkbutton c8" onclick="submitForm()" style="width:80px">提交</a>
                                          <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">重置</a>
                                   </div>
                            </div>
                          </div>
        </div>
	</body>
       <script type="text/javascript">
              function submitForm(){
                     $('#ff').form('submit',{
                            onSubmit:function(){
                                   var valid = $(this).form('enableValidation').form('validate');
                                   var data = {},userform = document.querySelector("form");
                                   if(valid){
                                        data.username = userform.username.value;
                                        data.password = userform.password.value;
                                        data.department = userform.department.value;
                                        data.role = userform.role.value;
                                        $.ajax({
                                            url:config.url+"/user/add",
                                            type:'post',
                                            data:data,
                                            xhrFields:{withCredentials:true},
                                            success:function(data){
                                                 if(data.code==200){
                                                        $.messager.alert("提示","添加成功.");
                                                 }
                                            },
                                            error:function(data){
                                                 console.log(data);
                                            }
                                        }); 
                                   }
                                   return false;
                            }
                     });

              }
              function clearForm(){
                     $("#ff").form("clear");
              }
       </script>
</html>